package cn.snailhd.server.user.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext;

import com.alibaba.fastjson.JSONObject;

import cn.snailhd.core.base.dao.MyBatisDao;
import cn.snailhd.core.base.dao.RedisDao;
import cn.snailhd.core.base.domain.BaseResultDTO;
import cn.snailhd.server.user.domain.LoginDTO;
import cn.snailhd.server.user.service.UserService;



@Controller
@RequestMapping(value="/user")
public class UserController {

	@Autowired
	MyBatisDao dao;
	
	@Autowired
	WebApplicationContext content;
	
	@Autowired
	RedisDao redis;
	
	@Autowired
	UserService userService;

	
	@RequestMapping(value="/redis/{key}/{value}")
	@ResponseBody
	public String main(@PathVariable String key,@PathVariable String value){
		BaseResultDTO re = new BaseResultDTO();
		
		redis.set(key, value);
		String val = redis.get(key);

        JSONObject obj1 = new JSONObject();
        obj1.put("val",val);
		re.setResult(obj1);
		return re.toJSON();
	}
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public String login(@RequestBody LoginDTO loginDTO) throws Exception{
		BaseResultDTO re = new BaseResultDTO();
		userService.login(loginDTO, re);
		return re.toJSON();
	}
	
		
	
}
